/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Project: jse2303 - Dir1
 * <p>Powered by webrx On 2023-07-20 17:32:42
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Dir1 {
    public static void main(String[] args) {
        //读取目录
        String path = "D:\\download";
        File f = new File(path);
        //System.out.println(f.isFile()); //false
        //System.out.println(f.isDirectory());//true 是目录存在

        Map<String, Integer> map = new HashMap<>();
        if (f.isDirectory()) {
            File[] fs = f.listFiles();
            for (File ff : fs) {
                //System.out.println(ff.getName());
                if (ff.isFile()) {
                    String fn = ff.getName();
                    if (fn.contains(".")) {
                        String ex = fn.substring(fn.lastIndexOf(".") + 1);
                        if (map.containsKey(ex)) {
                            map.put(ex, map.get(ex) + 1);
                        } else {
                            map.put(ex, 1);
                        }
                    } else {
                        if (map.containsKey("unknow")) {
                            map.put("unknow", map.get("unkonw") + 1);
                        } else {
                            map.put("unknow", 1);
                        }
                    }
                }
            }

            System.out.println(map);
        }
    }
}
